package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.myapplication.adapter.Adapter;


public class ThreeActivity extends AppCompatActivity {
    private ListView listView;
    private String[] usernames;
    private String[] scores;
    private String[] shuliangs;
    private String[] jiages;
    private int[] headImgs;
    private int[] imgs;
    private int[] imgss;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.three_activity_layout);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        listView = findViewById(R.id.listview);
    }

    private void initData() {
        usernames = new String[]{"烤鸭","回锅肉","茄子","宫保鸡丁"};
        scores = new String[]{"烤鸭烤鸭烤鸭烤鸭烤鸭烤鸭","回锅肉回锅肉回锅肉回锅肉回锅肉回锅肉","茄子茄子茄子茄子茄子茄子","宫保鸡丁宫保鸡丁宫保鸡丁宫保鸡丁宫保鸡丁宫保鸡丁"};
        shuliangs = new String[]{"0","0","0","0"};
        jiages = new String[]{"88.0元/份","12.3元/份","1.0元/份","0.2元/份"};
        headImgs = new int[]{R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,R.drawable.add,R.drawable.sub};
        listView.setAdapter(new Adapter(ThreeActivity.this, usernames, scores, shuliangs, jiages, headImgs));
    }

    private void initEvent() {
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(ThreeActivity.this,DetailActivity.class);
                intent.putExtra("name",usernames[position]);
                intent.putExtra("content",scores[position]);
                intent.putExtra("name2",jiages[position]);
                intent.putExtra("foot",headImgs[position]);
                startActivity(intent);
            }
        });

    }

}
